﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ICTBilling;

public partial class WebForms_Bill : System.Web.UI.Page
{
    private static List<ExceptionHandler> ExecutionCollection = new List<ExceptionHandler>();
    protected void Page_Load(object sender, EventArgs e)
    {
        BillMultiView.SetActiveView(BillShowView);
    }
    protected void SearchImageButton_Click(object sender, ImageClickEventArgs e)
    {
        BillGridView.PageSize = (PageSizeDropDownList.SelectedIndex == -1 || PageSizeDropDownList.SelectedValue == "0" ? 5 : Convert.ToInt32(PageSizeDropDownList.SelectedValue));
        if (CenterNameDropDownList.SelectedValue != "0" ||
            TypeDropDownList.SelectedValue != "0")
        {
            BillFormView.ChangeMode(FormViewMode.Insert);
            ClearImageButton.OnClientClick = string.Empty;
        }
        else
            ClearImageButton_Click(sender, e);
    }
    protected void ClearImageButton_Click(object sender, ImageClickEventArgs e)
    {
        CenterNameDropDownList.SelectedValue = TypeDropDownList.SelectedValue = "0";
        BillFormView.ChangeMode(FormViewMode.Insert);
        ClearImageButton.OnClientClick = "return false;";

    }
    protected void NewImageButton_Click(object sender, ImageClickEventArgs e)
    {
        BillMultiView.SetActiveView(EditView);
        BillFormView.ChangeMode(FormViewMode.Insert);
        BillFormView.DataBind();
    }
    protected void BillGridView_SelectedIndexChanged(object sender, EventArgs e)
    {
        BillFormView.PageIndex = (BillGridView.PageSize * BillGridView.PageIndex) + BillGridView.SelectedIndex;
        BillFormView.ChangeMode(FormViewMode.Edit);
        BillFormView.DataBind();
        if (((DropDownList)BillFormView.FindControl("TypeDropDownList")).SelectedValue == "2")
        {
            ((Label)BillFormView.FindControl("UsedValueLabel1")).Text = "کیلو وات";
        }
        else
        {
            ((Label)BillFormView.FindControl("UsedValueLabel1")).Text = "متر مکعب";
        }

        BillMultiView.SetActiveView(EditView);
        BillGridView.SelectedIndex = -1;
    }
    protected void BillEntityDataSource_Command(object sender, EntityDataSourceChangedEventArgs e)
    {
        tbBill newsItem = e.Entity as tbBill;
        if (e.Entity != null)
            ExecutionCollection.AddRange(newsItem.Validate(BillFormView.CurrentMode == FormViewMode.Edit ? ChangeAction.Update : ChangeAction.Insert));

        BillGridView.DataBind();
        BillMultiView.SetActiveView(BillShowView);
    }
   
}